package com.ask.clonedemo;

public class ShallowCopyExample {
    public static void main(String[] args) {
        Point center = new Point(5, 10);
        Circle circle1 = new Circle(10, center);
        try {
            Circle circle2 = (Circle) circle1.clone(); // 浅拷贝
            System.out.println("Before change:");
            System.out.println("Circle1 center: (" + circle1.center.x + ", " + circle1.center.y + ")");
            System.out.println("Circle2 center: (" + circle2.center.x + ", " + circle2.center.y + ")");

            // 修改circle2的中心点
            circle2.center.x = 15;
            circle2.center.y = 20;

            System.out.println("After change:");
            System.out.println("Circle1 center: (" + circle1.center.x + ", " + circle1.center.y + ")");
            System.out.println("Circle2 center: (" + circle2.center.x + ", " + circle2.center.y + ")");
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
    }
}
